package com.example.controller;
import com.example.common.Result;
import com.example.entity.FlTrainingTask;
import com.example.service.FLTrainingTaskService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * ClassName: FLTrainingTaskController
 * Package: com.example.controller
 * Description:
 *
 * @Author achb
 * @Create 2025/3/30 11:42
 * @Version 1.0
 */
@RestController
@RequestMapping("/fltrainingtask")
public class FLTrainingTaskController {

    @Resource
    private FLTrainingTaskService flTrainingTaskService;

    /**
     * 新增训练任务
     */
    @PostMapping("/add")
    public Result add(@RequestBody FlTrainingTask flTrainingTask) {
        flTrainingTaskService.add(flTrainingTask);
        return Result.success("Training task added successfully");
    }

    /**
     * 删除训练任务
     */
    @DeleteMapping("/delete/{taskId}")
    public Result deleteById(@PathVariable String taskId) {
        flTrainingTaskService.deleteByID(taskId);
        return Result.success("Training task deleted successfully");
    }

    /**
     * 更新训练任务信息
     */
    @PostMapping("/update")
    public Result updateById(@RequestBody FlTrainingTask flTrainingTask) {
        flTrainingTaskService.update(flTrainingTask);
        return Result.success("Training task updated successfully");
    }

    /**
     * 根据ID查询训练任务
     */
    @GetMapping("/selectById/{taskId}")
    public Result selectById(@PathVariable String taskId) {
        FlTrainingTask task = flTrainingTaskService.getByID(taskId);
        if (task != null) {
            return Result.success(task);
        } else {
            return Result.error("202", "Training task not found");
        }
    }

    /**
     * 查询所有训练任务
     */
    @GetMapping("/selectAll")
    public Result selectAll(FlTrainingTask flTrainingTask) {
        List<FlTrainingTask> list = flTrainingTaskService.getAll(flTrainingTask);
        return Result.success(list);
    }

    /**
     * 分页查询训练任务
     */
    @GetMapping("/selectPage")
    public Result selectPage(FlTrainingTask flTrainingTask,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<FlTrainingTask> page = flTrainingTaskService.selectPage(flTrainingTask, pageNum, pageSize);
        return Result.success(page);
    }

}